package wxdb.storage;
import wxdb.ui.Global;

public class Page {
	private byte content[];
	private int databaseID;
	private int pageID;
	private int refer;
	private boolean beClean;
	private boolean pin;
	
	public Page(byte con[], int dbID, int pID){
		content = new byte[Global.STORAGE_PAGE_SIZE];
		setContent(con);
		setDataBase(dbID);
		setPageID(pID);
		refer = 0;
		beClean = false;
		pin = false;
	}
	
	
	public void unpin(){
		pin = false;
	}
	
	public void pin(){
		pin = true;
	}
	
	public boolean bePined(){
		return pin;
	}
	
	public void setBeClean(){
		beClean = true;
		for(int i=0;i<Global.STORAGE_BUFFER_SIZE;i++)
			content[i]='\0';
	}
	
	public boolean getBeClean(){
		return beClean;
	}
	
	public int getPageID(){
		return pageID;
	}
	
	public void setPageID(int pID){
		pageID = pID;
	}
	
	public int getRefer(){
		return refer;
	}
	
	public void addRefer(){
		refer++;
	}
	
	public void refDown(){
		refer = refer/2;
	}
	
	public int getDataBaseID(){
		return databaseID;
	}

	public void setDataBase(int ID){
		databaseID = ID;
	}
	
	public byte[] getContent(){
		return content;
	}
	
	public void setContent(byte con[]){
		for(int i=0;i<Global.STORAGE_BUFFER_SIZE;i++)
			content[i]=con[i];
	}
	
	public void print(){
		char tmp[] = new char[Global.STORAGE_PAGE_SIZE];
		for(int i=0; i<Global.STORAGE_PAGE_SIZE;i++)
			tmp[i] = (char)content[i];
		System.out.println(tmp);
	}
}
